package com.LeeCode;

/**
 * 二叉树的最小深度
 */

public class Code111 {
    public static void main(String[] args) {
        Integer[] arr = {2, null, 3, null, 4, null, 5, null, 6};
        TreeNode root = Utils.buildTree(arr);
        System.out.println(new Code111().minDepth(root));
    }

    public int minDepth(TreeNode root) {
        if (root == null) return 0;
        if (root.left == null)
            return 1 + minDepth(root.right);
        if (root.right == null)
            return 1 + minDepth(root.left);

        return 1 + Math.min(minDepth(root.left), minDepth(root.right));
    }
}
